//
//  DayDetailViewCell.swift
//  YOKO
//
//  Created by Zoe_G on 16/5/5.
//  Copyright © 2016年 15Tec. All rights reserved.
//

import UIKit

class DayDetailViewCell: UITableViewCell {

    @IBOutlet weak var iconView: DayViewIconView!
    @IBOutlet weak var endTimeLabel: UILabel!
    @IBOutlet weak var beginTimeLabel: UILabel!
    @IBOutlet weak var eventView: UIView!
    @IBOutlet weak var eventTitleLable: UILabel!
    @IBOutlet weak var eventDescriptionLabel: UILabel!
    
    @IBOutlet weak var leftView: UIView!
	var event: EventInDayView! {
		didSet {
			self.setNeedsDisplay()
		}
	}

	override func awakeFromNib() {
		super.awakeFromNib()
		// Initialization code
        leftView.layer.cornerRadius = 2.0
        
        eventView.layer.cornerRadius = 2.5
        eventView.layer.shadowOffset = CGSizeMake(0, 1)
        eventView.layer.shadowColor = UIColor.lightGrayColor().CGColor
        eventView.layer.shadowRadius = 2.0
        eventView.layer.shadowOpacity = 0.4
        
        let eventViewTapGesture = UITapGestureRecognizer(target: self, action: #selector(DayDetailViewCell.eventViewTapHandler))
        eventView.addGestureRecognizer(eventViewTapGesture)
	}

	override func drawRect(rect: CGRect) {
        //Icon部分
        DrawUtil.drawLine(CGPointMake(40, 12), end: CGPointMake(70, 12), withColor: YOKOColor.TypeColors[event.colorType], withWidth: 1)
        iconView.layer.cornerRadius = 12.0
        iconView.eventColor = event.colorType
        iconView.iconType = event.eventType
        iconView.setNeedsDisplay()
        
        leftView.backgroundColor = YOKOColor.TypeColors[event.colorType]
        
        //卡片部分
        beginTimeLabel.text = event.eventBeginTime
        endTimeLabel.text = event.eventEndTime
        
        eventTitleLable.text = event.eventTitleText
        eventDescriptionLabel.text = event.eventDescription

	}
    
    //MARK: - Handler
    func eventViewTapHandler() {
        let rootNavigationController = (UIApplication.sharedApplication().delegate as! AppDelegate).navigationController
        let newEventViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("NewEventViewController") as! NewEventViewController

        newEventViewController.editState = true
        newEventViewController.event = event.event
        rootNavigationController.pushViewController(newEventViewController, animated: true)
    }
}
